/*
 * @Author: wuchao66_Git 2803670835@qq.com
 * @Date: 2023-02-14 14:48:51
 * @LastEditors: wuchao66_Git 2803670835@qq.com
 * @LastEditTime: 2023-11-13 20:19:14
 * @FilePath: \t154xgapptest\src\store\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import Vuex from 'vuex'
import { USERLOGIN, USERLOGOUT, SETCRUMBOBJ } from '../store/types'

Vue.use(Vuex)

const state = {
  isLogin: false,
  token: null,
  crumbObj: {}
}

const mutations = {//转变
  /*用户登录*/
  [USERLOGIN](state, payload) {
    state.isLogin = true
    state.token = payload
    window.sessionStorage.setItem('token', payload)
    window.sessionStorage.setItem('isLogin', true)
  },
  /*用户注销*/
  [USERLOGOUT](state) {
    state.isLogin = false
    state.token = null
    window.sessionStorage.clear('token')
    window.sessionStorage.clear('isLogin')
  },
  /*面包屑*/
  [SETCRUMBOBJ](state, payload) {
    state.crumbObj = payload
    window.sessionStorage.setItem('crumbObj', JSON.stringify(payload))
  }
}

const getters = {
  token: (state) => state.token
}

export default new Vuex.Store({
  // state:{
  //   token:null
  // },
  // mutations:{
  //   setToken(state,token){
  //       state.token=token;
  //   }
  // },
  state,
  mutations,
  getters
})//面包屑应该是我们在项目中经常使用的一个功能,一般情况下它用来表示我们当前所处的站点位置,也可以帮助我们能够更快的回到上个层级
